﻿<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@page import="com.infodms.dms.po.TcRolePO"%>
<%@page import="com.infodms.dms.common.Constant"%>
<%@ page import="com.infodms.dms.common.FileConstant"%>
<%@page import="java.util.List"%>
<%
	String contextPath = request.getContextPath();
	TcRolePO rolePO = (TcRolePO)request.getAttribute("rolePO");
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=7">
<link href="<%=contextPath%>/style/content.css" rel="stylesheet" type="text/css" />
<link href="<%=contextPath %>/style/calendar.css" rel="stylesheet" type="text/css" />
<link href="<%=contextPath%>/style/dtree1.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="<%=contextPath%>/js/jslib/mootools.js"></script>
<script type="text/javascript" src="<%=contextPath %>/js/web/mtcommon.js"></script>
<script type="text/javascript" src="<%=contextPath %>/js/framecommon/default.js"></script>
<script type="text/javascript" src="<%=contextPath%>/js/validate/validate.js"></script>
<script type="text/javascript" src="<%=contextPath%>/js/web/dtree.js"></script>
<script type="text/javascript" src="<%=FileConstant.codeJsUrl%>"></script>
<script type="text/javascript" src="<%=contextPath%>/js/dict.js"></script>
<script type="text/javascript" src="<%=contextPath %>/js/jslib/dialog_new.js"></script>
<title>系统角色维护</title>
<script>
	   var filecontextPath="<%=contextPath%>";
</script>
<script type="text/javascript">
	var tree_root_id = {"tree_root_id" : ""};
	var subStr = "funlist";
	var addNodeId;
	var tgjzw = "<%=request.getAttribute("gjzw") %>";
	var roleId = "<%=request.getAttribute("funList") %>";
	var tree_url = "<%=contextPath%>/sysmng/sysrole/ActionSysRole/initFunTree.json";
	var getFun_url = "<%=contextPath%>/sysmng/sysrole/ActionSysRole/getFunByRoleID.json";
	var path = "<%=contextPath%>";

	var roleSearch = "<%=contextPath%>/sysmng/sysrole/ActionSysRole/querySysRoleInit.do";
	function toGoRoleSearch() {
		window.location = roleSearch;
	}
	
	function pageload() {
		$('dtree').setHTML("<img src='"+path+"/img/tree/loading.gif' />载入中...");
		
		
		if(tgjzw != null && tgjzw != "") {
			var arrs = tgjzw.split(",");
			for(var i=0; i < arrs.length; i++) {
				$(arrs[i]).checked = true;
			}
		}

		myresize();

		sendAjax(tree_url,createTree,'myfm');
		
	}

	function myresize() {
		var ww = document.body.clientWidth;
		var hh = document.body.clientHeight;
		$('dtree').setStyle("left",(ww-300)/2);
		$('dtree').setStyle("height",(hh-350-25) < 0 ? "430" : (hh-350-25));
		$('treetd').setStyle("height",$('dtree').getStyle("height").toInt()+25);
		$('dtree').setStyle("display","");
	}

	PPPID = "10090102,10090101";
	function setsele2() {
		a.chkclickByFunId(PPPID);
	}

	function selType(obj,sgmCode,dealerCode) {
		if(obj.value == sgmCode) {
			$('dtree').setHTML("<img src='"+path+"/img/tree/loading.gif' />载入中...");
			sendAjax(tree_url,createTree,'myfm');
		}else if(obj.value == dealerCode) {
			$('dtree').setHTML("<img src='"+path+"/img/tree/loading.gif' />载入中...");
			sendAjax(tree_url,createTree,'myfm');
		}
	}

	var tree_script;

	function createTree(reobj) {

		$('dtree').empty();
		tree_script = new Element('script');
		tree_script.setText(" a = new dTree('a','dtree','true','true');");
	 	tree_script.injectInside($('dtree'));

		a.config.folderLinks=true;

		a.config.closeSameLevel=false;
	
		a.delegate=function (id)
		{
			addNodeId = a.aNodes[id].id;
		    var nodeID = a.aNodes[id].id;
		    
		    for(var n=0; n<a.aNodes.length; n++) {
		    	if(a.aNodes[n].id.contains(addNodeId+"01")) {
		    		return;
		    	}
		    }
		}
	
		var funlistobj = reobj[subStr];
		var funcCode,parFuncId,funcId,funcName;
		for(var i=0; i<funlistobj.length; i++) {
			parFuncId = funlistobj[i].parFuncId;
			funcId = funlistobj[i].funcId;
			funcName = funlistobj[i].funcName;
			if(parFuncId == 0) { //系统根节点
				a.add(funcId,"-1",funcName);
			} else if(funcId.length<=10){
				a.add(funcId,parFuncId,funcName);
			}
		}
	
		a.draw();

		a.openAll();

		if($('ROLE_TYPE').value == "<%=rolePO.getRoleType() %>") {
			setsele();
		}	
		setsele2();

	
	}

	function setsele() {
	
		var myf = "";
		if(roleId == "" || roleId.indexOf(",") == -1) {
			return false;
		}
		
		myf = roleId.split(",");
		for(var i=0; i<myf.length; i++) {

			a.chkclickByFunId(myf[i]);
		}
	}

/*	
	function getFunList() {
		var flist = new Array();
		for(var n=0; n<a.aNodes.length; n++) {
			var tid = a.aNodes[n].id;
			var tsrc = $('ckk' + a.obj + a.aNodes[n]._ai).src;
			if(tid.length == 8 && tsrc.contains("/checked.gif")) {
				flist.push(tid);
			}
		}
		return flist;
	}
*/
	function getFunList() {
		var flist = new Array();
		for(var n=0; n<a.aNodes.length; n++) {
			var tid = a.aNodes[n].id;
			var tsrc = $('ckk' + a.obj + a.aNodes[n]._ai).src;
			var tsrc0 = $('i' + a.obj + a.aNodes[n]._ai).src;
			if(tsrc0.contains("/leaf.gif")  && tsrc.contains("/checked.gif")) {
				flist.push(tid);
			}
		}
		return flist;
	}
	
	
	function sub(url) {
		
		
		
		$('FUNS').value = getFunList().toString();
		$('ROLE_NAME').value = $('ROLE_NAME').value.clean();
		$('ROLE_DESC').value = $('ROLE_DESC').value.clean();
		$('ROLE_ID').value = <%=rolePO.getRoleId() %>;
		submitForm($('myfm')) ? sendAjax(url,addRoleCallBack,'myfm') : "";
	}

	function addRoleCallBack(json) {
		if(json.st != null && json.st == "succeed") {
			toGoRoleSearch();
		}else if(json.st == "roleDesc_error") {
			showError('ermsg','erdiv','ROLE_DESC','角色名称重复,请重新输入!',170);
			$('ROLE_DESC').select();
		}
	}

	function toGoRoleSearch() {
		window.location = roleSearch;
	}
</script>
</head>
<body >
<div class="navigation"><img src="<%=contextPath%>/img/nav.gif" />&nbsp;当前位置： 系统管理 &gt; 用户管理 &gt; 系统角色维护</div>
<form action="" id="myfm">
<input type="hidden" id="ROLE_NAME" name="ROLE_NAME" />
<input type="hidden" id="ROLE_ID" name="ROLE_ID" />
<input type="hidden" id="FUNS" name="FUNS" />
<table class="table_query" border="0" style="border: 1px solid #DAE0EE">
	<tr>
		<td class="table_query_2Col_label_4Letter" nowrap="nowrap">角色类别：</td>
		<td class="table_query_2Col_input" nowrap="nowrap">
		<script type="text/javascript"> genSelBox("ROLE_TYPE",<%=Constant.SYS_USER%>,"<%=String.valueOf(rolePO.getRoleType()) %>",false,"","onchange='selType(this,<%=Constant.SYS_USER_SGM%>,<%=Constant.SYS_USER_DEALER%>)'");
			
		</script>
		</td>
		<td class="table_query_2Col_label_4Letter" nowrap="nowrap">角色代码：</td>
		<td class="table_query_4Col_input" nowrap="nowrap" id="rolen"><%=rolePO.getRoleName() %></td>
	</tr>
	<tr>
		<td class="table_query_2Col_label_4Letter" nowrap="nowrap">角色名称：</td>
		<td class="table_query_2Col_input" nowrap="nowrap"><input maxlength="30" datatype="0,is_null,30" class="middle_txt" type="text" id="ROLE_DESC" name="ROLE_DESC" value="<%=rolePO.getRoleDesc() %>" /></td>
		<td class="table_query_2Col_label_4Letter" nowrap="nowrap">状态：</td>
		<td class="table_query_2Col_input" nowrap="nowrap"><script
			type="text/javascript">genSelBox("ROLE_STATUS",<%=Constant.STATUS%>,<%=rolePO.getRoleStatus() %>,false,"","");</script>
		</td>
	</tr>
</table>
</form>
<br />
<table width="100%">
	<tr>
		<td align="center"><input type="button" value="保 存" class="normal_btn"
			onclick="sub('<%=contextPath%>/sysmng/sysrole/ActionSysRole/sysRolemodfi.json')" />
		<input type="button" value="返 回" class="normal_btn"
			onclick="toGoRoleSearch()" /></td>
	</tr>
</table>
<br />
<table class="de_table_list" style="border-bottom:0px solid #DAE0EE">
	<tr class="table_list_th">
		<td><img class="nav" src="<%=contextPath%>/img/subNav.gif" />&nbsp;功能列表</td>
	</tr>
	<tr class="table_list_th">
		<td valign="top" style="padding:10px;" id="treetd">
			<div id='dtree' class="dtree" style="border:1px solid #5E7692;width: 300px;height:350px; position: absolute;overflow:auto">
			</div>
		</td>
	</tr>
</table>
<br />

<div id="erdiv" style="position: absolute; top:-1000px; background: #FDFFCE; height: 17px; border:1px solid #FFBA43; display: none;">
<img style="margin-top: 1px; margin-left: 2px;" src="<%=contextPath%>/img/exclamation.gif" />
<span id="ermsg" style="color: red; position: absolute; margin-top: 1px;"></span></div>
</body>
<script language="javascript">
   pageload();
</script>
</html>
